<template>
  <view class="userLayout pageBg">


    <view class="userInfo" @click="goToLogin" v-if="Object.keys(member).length === 0">
      <view class="avatar">
        <image :src="member.avatar" mode="aspectFill"></image>
      </view>
      <view class="nickname1">登录后获取更多权益</view>
    </view>

    <view class="userInfo" v-else>
      <view class="avatar" @click="goToCenter">
        <image :src="member.avatar" mode="aspectFill"></image>
      </view>
      <!-- 	<view class="ip">100.100.100.100</view>
        <view class="address">来自于：河南</view> -->
      <view class="nickname">{{ member.nickname }}</view>
      <view class="istype">{{ member.isType == 0 ? "学员" : "讲师" }}</view>
    </view>
    <view class="section">
      <view class="list">
        <navigator url="/pages/purchasedCourse/purchasedCourse" class="row">
          <view class="left">
            <uni-icons type="download-filled" size="20"></uni-icons>
            <view class="text">已购课程</view>
          </view>
          <view class="right">
            <!-- <view class="text">33</view> -->
            <uni-icons type="right" size="20"></uni-icons>
          </view>
        </navigator>
        <navigator url="/pages/collection/collection" class="row">
          <view class="left">
            <uni-icons type="star-filled" size="20"></uni-icons>
            <view class="text">我的收藏</view>
          </view>
          <view class="right">
            <!-- <view class="text">{{}}</view> -->
            <uni-icons type="right" size="20"></uni-icons>
          </view>
        </navigator>

        <!-- 我的申请 -->
        <!-- start -->
        <navigator url="/pages/user/myapply" class="row" v-if="isShow">
          <view class="left">
            <uni-icons fontFamily="myFont" size="19">{{ '\ue761' }}</uni-icons>
            <view class="text">我的申请</view>
          </view>
          <view class="right">
            <!-- <view class="text">{{}}</view> -->
            <uni-icons type="right" size="20" color="#aaa"></uni-icons>
          </view>
        </navigator>
        <!-- end -->

        <!-- 添加课程 -->
        <!-- start -->
        <view class="row" v-if="isShow1" @click="toAddCourse">
          <view class="left">
            <uni-icons fontFamily="myFont" size="19">{{ '\ue716' }}</uni-icons>
            <view class="text">添加课程</view>
          </view>
          <view class="right">
            <!-- <view class="text">{{}}</view> -->
            <uni-icons type="right" size="20" color="#aaa"></uni-icons>
          </view>
        </view>
        <!-- end -->

        <!-- 添加课程 -->
        <!-- start -->
        <view class="row" v-if="isShow1" @click="toMyCourse">
          <view class="left">
            <uni-icons fontFamily="myFont" size="19">{{ '\ue64d' }}</uni-icons>
            <view class="text">我的课程</view>
          </view>
          <view class="right">
            <!-- <view class="text">{{}}</view> -->
            <uni-icons type="right" size="20" color="#aaa"></uni-icons>
          </view>
        </view>
        <!-- end -->

        <view class="row">
          <view class="left">
            <uni-icons type="chatboxes-filled" size="20" color="#28b389"></uni-icons>
            <view class="text">联系客服</view>
          </view>
          <view class="right">
            <!-- <view class="text">33</view> -->
            <uni-icons type="right" size="20"></uni-icons>
          </view>
          <!-- #ifdef MP -->
          <button open-type="contact">联系客服</button>
          <!-- #endif -->
          <!-- #ifdef H5-->
          <button @click="clickContact">拨打电话</button>
          <!-- #endif -->
        </view>

      </view>
    </view>

    <view class="section">
      <view class="list">
        <view class="row">
          <view class="left">
            <uni-icons type="notification-filled" size="20"></uni-icons>
            <view class="text">订阅更新</view>
          </view>
          <view class="right">
            <view class="text"></view>
            <uni-icons type="right" size="15" color="#aaa"></uni-icons>
          </view>
        </view>
        <view class="row">
          <view class="left">
            <uni-icons type="flag-filled" size="20"></uni-icons>
            <view class="text">常见问题</view>
          </view>
          <view class="right">
            <view class="text"></view>
            <uni-icons type="right" size="15" color="#aaa"></uni-icons>
          </view>
        </view>


        <view class="row" v-if="Object.keys(member).length" @click="goToCenter">
          <view class="left">
            <uni-icons type="contact" size="20"></uni-icons>
            <view class="text">个人中心</view>
          </view>
          <view class="right">
            <view class="text"></view>
            <uni-icons type="right" size="15" color="#aaa"></uni-icons>
          </view>
        </view>

        <view class="row" v-if="Object.keys(member).length">
          <view class="left" @tap="logout">
            <uni-icons type="redo-filled" size="20"></uni-icons>
            <view class="text">退出登录</view>
          </view>
        </view>
      </view>


    </view>
  </view>
</template>

<script setup>
import {
  getApply, isTeacher
} from '../../apis/teacher.js'

import {exit} from "@/apis/user.js"

const isShow = ref(false)
const isShow1 = ref(false)
const clickContact = () => {
  uni.makePhoneCall({
    phoneNumber: "114"
  })

}

let member = uni.getStorageSync("member")
const getApplyList = async (phone) => {
  const res = await getApply(phone)
  if (res.data.data.length > 0) {
    isShow.value = true
  } else {
    isShow.value = false
  }
}
const getIsTeacher = async (phone) => {
  const res = await isTeacher(phone)
  if (res.data.code == 200) {
    isShow1.value = true
  } else {
    isShow1.value = false
  }
}
getIsTeacher(member.mobile)
getApplyList(member.mobile)
const toAddCourse = () => {
  uni.navigateTo({
    url: "/pages/teacher/addcourse"
  })
}
const toMyCourse = () => {
  uni.navigateTo({
    url: "/pages/teacher/courselist"
  })
}
const logout = async () => {

    let res = await exit()
    if (res.data.code == 200) {
      uni.removeStorageSync("member")
      uni.removeStorageSync("token")
      uni.removeStorageSync("BuyCourses")
      uni.removeStorageSync("collection")
      uni.removeStorageSync('historySearch')
      uni.showToast({
        title: "退出成功",
        icon: "none"
      })

      uni.redirectTo({
        url: "/pages/login/login",

      })
    }
}



	const goToCenter = () => {
			uni.navigateTo({
				url:'/pages/userCenter/userCenter'
			});
		}

	const goToLogin = () => {
			uni.navigateTo({
				url: '/pages/login/login'
			});
		}



</script>

<style lang="scss" scoped>
@font-face {
  font-family: myFont;
  src: url('../../static/ttf/iconfont.ttf');
}

.userLayout {
  .userInfo {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
			//padding: 50rpx 0rpx;

    .avatar {
      margin-top: 50px;
      width: 160rpx;
      height: 160rpx;
      border-radius: 50%;
      overflow: hidden;
				border: 2px solid #d3d3d3;
				margin-bottom: 15rpx;
      image {
        width: 100%;
        height: 100%;
      }

      .ip {
        font-size: 44rpx;
        color: #333;
        padding: 20rpx 0 5rpx;
      }

      .address {
        font-size: 28rpx;
        color: #aaa;
      }
    }


  }

  .section {
    width: 690rpx;
    margin: 50rpx auto;
    border: 1px solid #eee;
    border-radius: 10rpx;
    box-shadow: 0 0 30rpx rgba(0, 0, 0, 0.05);

    .list {
      .row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 30rpx;
        height: 100rpx;
        border-bottom: 1px solid #eee;
        position: relative;
        background: #fff;

        &:last-child {
          border-bottom: 0;
        }

        .left {
          display: flex;
          align-items: center;

          :deep() {
            .uni-icons {
              color: $brand-theme-color !important;
            }
          }

          .text {
            padding-left: 20rpx;
            color: #666;
          }
        }

        .right {
          display: flex;
          align-items: center;

          .text {
            font-size: 28rpx;
            color: #aaa;
          }

        }

        button {
          position: absolute;
          top: 0;
          left: 0;
          height: 100rpx;
          width: 100%;
          opacity: 0;
        }

      }
    }
  }

  .logout {
    margin: 50rpx auto;
    width: 690rpx;
    height: 100rpx;
    background: #fff;
    border-radius: 10rpx;
    box-shadow: 0 0 30rpx rgba(0, 0, 0, 0.05);

    button {
      width: 100%;
      height: 100%;
      border-radius: 10rpx;
      background: $brand-theme-color;
      color: #fff;
      font-size: 30rpx;
      line-height: 100rpx;
      border: 0;
    }
  }
}
</style>
